package admin.controllers;

import java.io.IOException;
import java.net.URLDecoder;
import java.util.TreeMap;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import models.AutoSiteModel;

import admin.data.AutoSiteData;

public class DeleteSiteServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException {
		TreeMap check = new TreeMap();
		String path = ((HttpServletRequest) request).getRequestURI();
		String url = URLDecoder.decode(path.toLowerCase().replaceAll("/admin/delete-site/", ""),"UTF-8");
		
		AutoSiteData autoSiteData = new AutoSiteData();
		AutoSiteModel autoSite = autoSiteData.getSite(url);
		
		if (autoSite != null) {
			autoSiteData.delete(autoSite);
		}
		
		response.sendRedirect("/admin/list-site");
	}
}
